package br.mg.bhe.vertice;

import org.vertx.java.deploy.Verticle;
import org.vertx.java.core.Handler;
import org.vertx.java.core.http.HttpServerRequest;
import java.util.Map;
import java.io.File;

public class App extends Verticle {
  
  public void start() {
    Utils.startOfficeServer();
  
    vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
      public void handle(HttpServerRequest request) {
        Map<String, String> params = Utils.getDownloadParameters(request.query);
        String fileToSend = ConversionHandler
            .convert(new File(Utils.getFileHome() + "/" + params.get("file")), params.get("ext"));
        DownloadHandler.download(request.response, fileToSend);
      }
    }).listen(8124);
    
    System.out.println("Server running at http://127.0.0.1:8124");
  }
}
